<template>
  <div>
    <el-container class="home-container">
      <el-aside ref="aside" :width="isCollapse ? '65px' : '200px'">
        <el-menu
          router
          ref="menu"
          :collapse="isCollapse"
          :collapse-transition="false"
        >
          <div class="logo">
            <i class="el-icon-set-up"></i>
            <h1 v-show="!isCollapse">Manager</h1>
          </div>
          <el-menu-item index="/dashboard">
            <i class="el-icon-s-home"></i>
            <span slot="title">首页</span>
          </el-menu-item>
          <el-menu-item index="/user">
            <i class="el-icon-user-solid"></i>
            <span>用户管理</span>
          </el-menu-item>
          <el-menu-item index="/category">
            <i class="el-icon-menu"></i>
            <span>分类管理</span>
          </el-menu-item>
          <el-menu-item index="/article">
            <i class="el-icon-document"></i>
            <span slot="title">文章管理</span>
          </el-menu-item>
          <el-menu-item index="/messages">
            <i class="el-icon-chat-line-round"></i>
            <span>留言管理</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <div class="header-left">
            <i
              class="el-icon-s-fold"
              :class="isCollapse ? 'isCollapse' : ''"
              @click="handleCollapse"
            ></i>
          </div>
          <div class="title">个人博客管理系统</div>
          <el-dropdown>
            <el-avatar>
              <img src="../../assets/images/user.gif" alt="" />
            </el-avatar>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>
                <el-button type="text" @click="logout">退出登录</el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button type="text" @click="logtomain">返回博客</el-button>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-header>
        <el-main><router-view /></el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: 'Home',
  data() {
    return {
      isCollapse: true,
    }
  },
  mounted() {
    this.$refs['menu'].activeIndex = this.$route.path
  },
  methods: {
    handleCollapse() {
      // 切换状态
      this.isCollapse = !this.isCollapse
      // 改变el-aside的宽度
    },
    logout() {
      localStorage.removeItem('token')
      this.$router.push('/login')
    },
    logtomain() {
      localStorage.removeItem('token')
      location.href = 'http://localhost:5500/'
    },
  },
}
</script>

<style>
.home-container {
  height: 100vh;
}
.el-aside {
  background-color: #fff;
}
.title {
  margin: 0 auto;
  font-family: '楷体';
  font-size: 30px;
}
.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #fff;
  font-size: 24px;
}
.el-header i {
  transition: all 0.3s;
}
.el-main {
  background-color: #f5f5f5;
}
.logo {
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  height: 60px;
  background-color: #409eff;
  font-size: 25px;
  color: #fff;
}
.isCollapse {
  transform: rotate(-180deg);
}
.home-menu {
  width: 200px;
  transition: all 0.3s;
}
.collapse-menu {
  width: 64px;
}
/* .header-left {
  display: flex;
  justify-content: space-evenly;
  width: 200px;
  font-size: 20px;
} */
.header-left a {
  text-decoration: none;
  color: black;
}
.header-left:hover {
  cursor: pointer;
}
</style>
